import willView from '../views/will.art'
import expectedView from '../views/expected.art'
import  expectedmodule from '../models/movie'
import wantseeView from '../views/want-see.art'
import cityId  from './moviecontrollers'
const BScroll = require('better-scroll');
class will{
    constructor(){
       this.id=[],
       this.list=[],
       this.index=0,
       this.data=[]
    }
    renderer(list){
  let expectdhtml=expectedView({
      list
  })
   $('.img-list').html(expectdhtml)

    }
    
   wantseerender(data){
    let wantHtml=wantseeView({
     data
    })
      $('.wanted ul').html(wantHtml)
   }

  async  render(){
        let html=willView()
        $('main').html(html)
        var id=cityId.cathref()
      
   let result=await expectedmodule.expected(id) 
     let list=this.list=this.handleurl(result,'170.230')
    //console.log(list)
     this.renderer(list)

    let datalist=await expectedmodule.wantsee(id)
  
   let data=this.data=this.handleurl(datalist,'128.180')
   
      this.wantseerender(data)
    }

    handleurl(result,url){
        let re=/w.h/g
        let  len=result.coming.length
          for(let i=0;i<len;i++){
            result.coming[i].img=result.coming[i].img.replace(re, url)
      }
          let list=this.list=result.coming
          return list
      
      }
    
}

export default new will()